package com.guomao.stream;

import java.util.ArrayList;

public class StreamDemoA {

    public static void main(String[] args) {


//        method1();


        ArrayList<String> list = new ArrayList<>();

        list.add("张三");
        list.add("张无忌");
        list.add("张三丰");
        list.add("殷素素");


        list.stream().
                filter((name) -> name.startsWith("张")).
                filter(name -> name.length() >= 3).
                forEach(System.out::println);
    }

    private static void method1() {
        ArrayList<String> list = new ArrayList<>();

        list.add("张三");
        list.add("张无忌");
        list.add("张三丰");
        list.add("殷素素");

        String s1 = list.get(0);
        String s2 = list.get(1);
        String s3 = list.get(2);

        ArrayList<String> result1 = new ArrayList<>();
        for (String s : list) {
            boolean flag = s.startsWith("张");
            if (flag) {
                result1.add(s);
            }
        }

//        System.out.println(result1);
        ArrayList<String> result2 = new ArrayList<>();
        for (String s : result1) {
            int length = s.length();
            if (length >= 3) {
                result2.add(s);
            }
        }
    }
}
